home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / os20 / wb / toolmanager2_0.lha / ToolManager / Source / library / safety.c < prev    next >
C/C++ Source or Header  |  1992-09-26  |  2KB  |  99 lines

  1. /*
  2.  * safety.c  V2.0
  3.  *
  4.  * safe delete functions
  5.  *
  6.  * (c) 1990-1992 Stefan Becker
  7.  */
  8.  
  9. #include "ToolManagerLib.h"
  10.  
  11. /* Delete a CxObject and remove all associated messages from the BrokerPort */
  12. void SafeDeleteCxObjAll(struct CxObj *cxobj, struct TMLink *tml)
  13. {
  14.  CxMsg *msg;
  15.  
  16.  /* Delete object */
  17.  DeleteCxObjAll(cxobj);
  18.  
  19.  /* Scan message port list */
  20.  Forbid();
  21.  msg=GetHead(&BrokerPort->mp_MsgList);
  22.  while (msg)
  23.   /* Does the message point to this object? */
  24.   if ((struct TMLink *) CxMsgID(msg)==tml) {
  25.    /* Yes */
  26.    struct CxMsg *nextmsg=GetSucc(msg);
  27.  
  28.    /* Remove it from list */
  29.    Remove((struct Node *) msg);
  30.  
  31.    /* Reply it */
  32.    ReplyMsg((struct Message *) msg);
  33.  
  34.    /* Get pointer to next message */
  35.    msg=nextmsg;
  36.   }
  37.    /* No. Get pointer to next message */
  38.   else msg=GetSucc(msg);
  39.  Permit();
  40. }
  41.  
  42. /* Remove all associated messages from the AppMsgPort */
  43. static void RemoveAppMsgs(struct TMLink *tml)
  44. {
  45.  struct AppMessage *msg;
  46.  
  47.  /* Scan message port */
  48.  Forbid();
  49.  msg=GetHead(&AppMsgPort->mp_MsgList);
  50.  while (msg)
  51.   /* Does the message point to this object? */
  52.   if ((struct TMLink *) msg->am_ID==tml) {
  53.    /* Yes */
  54.    struct AppMessage *nextmsg=GetSucc(msg);
  55.  
  56.    /* Remove it from list */
  57.    Remove((struct Node *) msg);
  58.  
  59.    /* Reply it */
  60.    ReplyMsg((struct Message *) msg);
  61.  
  62.    /* Get pointer to next message */
  63.    msg=nextmsg;
  64.   }
  65.    /* No. Get pointer to next message */
  66.   else msg=GetSucc(msg);
  67.  Permit();
  68. }
  69.  
  70. /* Delete an AppMenu and remove all associated messages from the AppMsgPort */
  71. void SafeRemoveAppMenuItem(void *appmenu, struct TMLink *tml)
  72. {
  73.  /* Remove AppMenu */
  74.  RemoveAppMenuItem(appmenu);
  75.  
  76.  /* Remove messages */
  77.  RemoveAppMsgs(tml);
  78. }
  79.  
  80. /* Delete an AppIcon and remove all associated messages from the AppMsgPort */
  81. void SafeRemoveAppIcon(void *appicon, struct TMLink *tml)
  82. {
  83.  /* Remove AppIcon */
  84.  RemoveAppIcon(appicon);
  85.  
  86.  /* Remove messages */
  87.  RemoveAppMsgs(tml);
  88. }
  89.  
  90. /* Delete an AppWindow and remove all associated messages from the AppMsgPort */
  91. void SafeRemoveAppWindow(void *appwin, struct TMLink *tml)
  92. {
  93.  /* Remove AppIcon */
  94.  RemoveAppWindow(appwin);
  95.  
  96.  /* Remove messages */
  97.  RemoveAppMsgs(tml);
  98. }
  99.